<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /*  margin+ position */
    /* .parent {
        width: 500px;
        height: 500px;
        border: 2px solid pink;
        position: relative;
    }

    .child {
        width: 100px;
        height: 100px;
        background-color: yellow;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        margin: auto;
    } */
    /* position 50% + margin -自身一半  （子元素已知宽高） */
    /*     
    .parent {
        width: 500px;
        height: 500px;
        border: 2px solid pink;
        position: relative;
    }

    .child {
        width: 100px;
        height: 100px;
        background-color: yellow;
        position: absolute;
        top: 50%;
        left: 50%;
        margin: -50px 0 0 -50px;
    } */
    /* position 50% + transform:translate(-50%,-50%)  （子元素未知宽高） */
    /*     
    .parent {
        width: 500px;
        height: 500px;
        border: 2px solid pink;
        position: relative;
    }

    .child {
        width: 100px;
        height: 100px;
        background-color: yellow;
        position: absolute;
        top: 50%;
        left: 50%;
        transform:translate(-50%,-50%)
    } */

    /* flex 布局 主侧轴居中*/
    /* .parent {
        width: 500px;
        height: 500px;
        border: 2px solid pink;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .child {
        width: 100px;
        height: 100px;
        background-color: yellow;
    } */
    /*  text-align  line-height 只适用于文本节点 */
    .parent {
        width: 500px;
        height: 500px;
        border: 2px solid pink;
        text-align: center;
        line-height: 500px;
    }

    .child {
        width: 100px;
        height: 100px;
        background-color: yellow;
    }
</style>

<body>
    <div class="parent">
        <div class="child"></div>
    </div>

</body>

</html>